home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++ FAQ Reference 1.0 / C++ FAQ Reference 1.0.rsrc / TEXT_1632.txt < prev    next >
Encoding:
Text File  |  1993-06-30  |  693 b   |  27 lines

  1. Use the following declaration:
  2.  
  3.     class Frob {
  4.     public:
  5.       Rettype f(T1 x, T2 y);
  6.       Rettype g(T1 x, T2 y);
  7.       Rettype h(T1 x, T2 y);
  8.       Rettype i(T1 x, T2 y);
  9.       //...
  10.     };
  11.  
  12.     Rettype (Frob::*fn_ptr[3])(T1,T2) = { &Frob::f, &Frob::g, &Frob::h };
  13.  
  14. You can make the array declaration somewhat clearer with a typedef:
  15.     typedef  Rettype (Frob::*Frob_member_ptr)(T1,T2);
  16.     //...
  17.     Frob_member_ptr fn_ptr[3] = { &Frob::f, &Frob::g, &Frob::h };
  18.  
  19. To call one of the functions on an object 'frob', use:
  20.     Frob frob;
  21.     //...
  22.     (frob.*fn_ptr[i])(x, y);
  23.  
  24. You can make the call somewhat clearer using a #define:
  25.     #define  apply_member_fn(object,fn)   ((object).*(fn))
  26.     //...
  27.     apply_member_fn(frob,fn_ptr[i])(x, y)